package com.assistant.common;

import org.springframework.context.annotation.Configuration;
import org.springframework.util.ResourceUtils;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import java.io.FileNotFoundException;

@Configuration
public class WebConfig implements WebMvcConfigurer {
    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        String absolutelyPath=null;
        System.out.println("配置文件已经生效");
        try {
            absolutelyPath =  ResourceUtils.getURL("src/main/resources/static/img").getPath();
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }
        registry.addResourceHandler("/img/**").addResourceLocations("file:" + absolutelyPath);
    }
}


